{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# SVG Turtle classic Module Demo\n",
    "\n",
    "This notebook demonstrates the three usage modes of the `svg_turtle_classic` module:\n",
    "1. Procedural style\n",
    "2. Module style\n",
    "3. Object-oriented style\n",
    "\n",
    "Along with various drawing functions."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Import Module"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Available functions: ['done', 'forward', 'pencolor', 'pensize', 'right', 'setup']\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "sys.path.append('..')\n",
    "\n",
    "# Re-import module to ensure all functions are available\n",
    "import svg_turtle_classic\n",
    "from svg_turtle_classic import *\n",
    "\n",
    "# Verify import success\n",
    "print(\"Available functions:\", [f for f in dir() if f in ['setup', 'forward', 'right', 'done', 'pencolor', 'pensize']])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Procedural Style Demo\n",
    "\n",
    "After using `from svg_turtle_classic import *`, you can call functions directly."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" baseProfile=\"full\" height=\"400px\" version=\"1.1\" width=\"600px\"><defs/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"300.5,200.5 400.5,200.5 400.5,300.5 300.5,300.5 300.5,200.5\" stroke=\"#0000ff\" stroke-linecap=\"round\" stroke-width=\"3\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"300.5,200.5 300.5,200.5\" stroke=\"#ff0000\" stroke-linecap=\"round\" stroke-width=\"10\"/><polygon clip-path=\"url(#border_clip)\" fill=\"black\" fill-rule=\"evenodd\" points=\"300.5,200.5 291.5,195.5 293.5,200.5 291.5,205.5\" stroke=\"#ff0000\" stroke-width=\"1\"/></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Set canvas size\n",
    "setup(600, 400)\n",
    "\n",
    "# Draw a simple square\n",
    "pencolor('blue')\n",
    "pensize(3)\n",
    "\n",
    "for _ in range(4):\n",
    "    forward(100)\n",
    "    right(90)\n",
    "\n",
    "# Draw a red dot at center\n",
    "penup()\n",
    "goto(0, 0)\n",
    "pencolor('red')\n",
    "dot(10)\n",
    "\n",
    "# Complete drawing and display\n",
    "done()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Module Style Demo\n",
    "\n",
    "After using `import svg_turtle_classic`, call functions through the module name."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" baseProfile=\"full\" height=\"400px\" version=\"1.1\" width=\"600px\"><defs/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"300.5,200.5 380.5,200.5 340.5,131.2179676972449 300.5,200.49999999999997\" stroke=\"#008000\" stroke-linecap=\"round\" stroke-width=\"2\"/><polygon clip-path=\"url(#border_clip)\" fill=\"black\" fill-rule=\"evenodd\" points=\"300.5,200.49999999999997 291.5,195.49999999999997 293.5,200.49999999999997 291.5,205.49999999999997\" stroke=\"#008000\" stroke-width=\"1\"/></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import svg_turtle_classic as stp\n",
    "\n",
    "# Set canvas size\n",
    "stp.setup(600, 400)\n",
    "\n",
    "# Draw a triangle\n",
    "stp.pencolor('green')\n",
    "stp.pensize(2)\n",
    "\n",
    "for _ in range(3):\n",
    "    stp.forward(80)\n",
    "    stp.left(120)\n",
    "\n",
    "# Complete drawing and display\n",
    "stp.done()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. Object-Oriented Style Demo\n",
    "\n",
    "Create Turtle objects for drawing."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" baseProfile=\"full\" height=\"400px\" version=\"1.1\" width=\"600px\"><defs/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"300.5,200.5 315.95084971874735,198.05282581475768 329.88926261462365,190.95084971874738 340.95084971874735,179.88926261462365 348.0528258147577,165.95084971874738 350.5,150.5 348.0528258147577,135.04915028125265 340.9508497187474,121.11073738537635 329.8892626146237,110.04915028125264 315.9508497187474,102.94717418524233 300.50000000000006,100.50000000000001 285.04915028125265,102.94717418524233 271.1107373853764,110.04915028125264 260.04915028125265,121.11073738537634 252.94717418524237,135.0491502812526 250.50000000000006,150.49999999999997 252.94717418524235,165.95084971874732 260.04915028125265,179.8892626146236 271.11073738537635,190.9508497187473 285.0491502812526,198.05282581475763 300.49999999999994,200.49999999999994\" stroke=\"#800080\" stroke-linecap=\"round\" stroke-width=\"4\"/><polygon clip-path=\"url(#border_clip)\" fill=\"black\" fill-rule=\"evenodd\" points=\"300.49999999999994,200.49999999999994 291.49999999999994,195.49999999999994 293.49999999999994,200.49999999999994 291.49999999999994,205.49999999999994\" stroke=\"#800080\" stroke-width=\"1\"/></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" baseProfile=\"full\" height=\"400px\" version=\"1.1\" width=\"600px\"><defs/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"350.5,150.5 410.5,150.5 361.95898033750314,185.7671151375484 380.5,128.70372415983917 399.04101966249686,185.7671151375484 350.5,150.5\" stroke=\"#ffa500\" stroke-linecap=\"round\" stroke-width=\"2\"/><polygon clip-path=\"url(#border_clip)\" fill=\"black\" fill-rule=\"evenodd\" points=\"350.5,150.5 341.5,145.50000000000003 343.5,150.50000000000003 341.5,155.50000000000003\" stroke=\"#ffa500\" stroke-width=\"1\"/></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from svg_turtle_classic import Turtle\n",
    "\n",
    "# Create two turtle objects\n",
    "t1 = Turtle()\n",
    "t2 = Turtle()\n",
    "\n",
    "# Set properties for the first turtle\n",
    "t1.pencolor('purple')\n",
    "t1.pensize(4)\n",
    "t1.speed(1)\n",
    "\n",
    "# Set properties for the second turtle\n",
    "t2.pencolor('orange')\n",
    "t2.pensize(2)\n",
    "t2.penup()\n",
    "t2.goto(50, 50)\n",
    "t2.pendown()\n",
    "\n",
    "# First turtle draws a circle\n",
    "t1.circle(50)\n",
    "\n",
    "# Second turtle draws a star\n",
    "for _ in range(5):\n",
    "    t2.forward(60)\n",
    "    t2.right(144)\n",
    "\n",
    "# Complete drawing for first turtle\n",
    "done(t1)\n",
    "\n",
    "# Complete drawing for second turtle\n",
    "done(t2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5. Advanced Features Demo\n",
    "\n",
    "Demonstrate fill, color gradients, text drawing, and other features."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" baseProfile=\"full\" height=\"600px\" version=\"1.1\" width=\"800px\"><defs/><polygon clip-path=\"url(#border_clip)\" fill=\"#add8e6\" fill-rule=\"evenodd\" points=\"300.5,350.5 500.5,350.5 500.5,250.5 300.5,250.49999999999997 300.5,350.5\" stroke-width=\"0\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"300.5,350.5 500.5,350.5 500.5,250.5 300.5,250.49999999999997 300.5,350.5\" stroke=\"black\" stroke-linecap=\"round\" stroke-width=\"2\"/><text clip-path=\"url(#border_clip)\" fill=\"black\" style=\"font-family: Arial; font-size: 26.4; font-style: bold;\" text-anchor=\"middle\" x=\"399.5\" y=\"293.3\">Hello SVG Turtle!</text><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"320.5,330.5 320.5,330.5\" stroke=\"#000000\" stroke-linecap=\"round\" stroke-width=\"8\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"360.5,330.5 360.5,330.5\" stroke=\"#280000\" stroke-linecap=\"round\" stroke-width=\"8\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"400.5,330.5 400.5,330.5\" stroke=\"#500000\" stroke-linecap=\"round\" stroke-width=\"8\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"440.5,330.5 440.5,330.5\" stroke=\"#780000\" stroke-linecap=\"round\" stroke-width=\"8\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"480.5,330.5 480.5,330.5\" stroke=\"#a00000\" stroke-linecap=\"round\" stroke-width=\"8\"/><polygon clip-path=\"url(#border_clip)\" fill=\"#add8e6\" fill-rule=\"evenodd\" points=\"480.5,330.5 471.5,325.5 473.5,330.5 471.5,335.5\" stroke=\"#a00000\" stroke-width=\"1\"/></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Set canvas\n",
    "setup(800, 600)\n",
    "\n",
    "# Draw a filled rectangle\n",
    "pencolor('black')\n",
    "fillcolor('lightblue')\n",
    "pensize(2)\n",
    "\n",
    "penup()\n",
    "goto(-100, -50)\n",
    "pendown()\n",
    "begin_fill()\n",
    "\n",
    "for _ in range(2):\n",
    "    forward(200)\n",
    "    left(90)\n",
    "    forward(100)\n",
    "    left(90)\n",
    "\n",
    "end_fill()\n",
    "\n",
    "# Draw text inside rectangle\n",
    "penup()\n",
    "goto(0, 0)\n",
    "write('Hello SVG Turtle!', align='center', font=('Arial', 16, 'bold'))\n",
    "\n",
    "# Draw some decorative dots\n",
    "for i in range(5):\n",
    "    penup()\n",
    "    goto(-80 + i * 40, -30)\n",
    "    pencolor(f'#{i*40:02x}0000')\n",
    "    dot(8)\n",
    "\n",
    "done()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6. Complex Graphics Demo\n",
    "\n",
    "Draw a spiral pattern."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" baseProfile=\"full\" height=\"600px\" version=\"1.1\" width=\"600px\"><defs/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"300.5,300.5 300.5,300.5\" stroke=\"#00ff80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"300.5,300.5 300.5,302.5\" stroke=\"#02fc80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"300.5,302.5 296.5,302.5\" stroke=\"#05f980\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"296.5,302.5 296.5,296.5\" stroke=\"#07f780\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"296.5,296.5 304.5,296.5\" stroke=\"#0af480\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"304.5,296.5 304.5,306.5\" stroke=\"#0cf280\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"304.5,306.5 292.5,306.5\" stroke=\"#0fef80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"292.5,306.5 292.5,292.5\" stroke=\"#11ed80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"292.5,292.5 308.5,292.5\" stroke=\"#14ea80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"308.5,292.5 308.5,310.5\" stroke=\"#16e880\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"308.5,310.5 288.5,310.5\" stroke=\"#19e580\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"288.5,310.5 288.5,288.5\" stroke=\"#1ce280\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"288.5,288.5 312.5,288.5\" stroke=\"#1ee080\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"312.5,288.5 312.5,314.5\" stroke=\"#21dd80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"312.5,314.5 284.5,314.5\" stroke=\"#23db80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"284.5,314.5 284.5,284.5\" stroke=\"#26d880\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"284.5,284.5 316.5,284.5\" stroke=\"#28d680\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"316.5,284.5 316.5,318.5\" stroke=\"#2bd380\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"316.5,318.5 280.5,318.5\" stroke=\"#2dd180\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"280.5,318.5 280.5,280.5\" stroke=\"#30ce80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"280.5,280.5 320.5,280.5\" stroke=\"#33cc80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"320.5,280.5 320.50000000000006,322.5\" stroke=\"#35c980\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"320.50000000000006,322.5 276.50000000000006,322.50000000000006\" stroke=\"#38c680\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"276.50000000000006,322.50000000000006 276.49999999999994,276.50000000000006\" stroke=\"#3ac480\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"276.49999999999994,276.50000000000006 324.49999999999994,276.49999999999994\" stroke=\"#3dc180\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"324.49999999999994,276.49999999999994 324.50000000000006,326.49999999999994\" stroke=\"#3fbf80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"324.50000000000006,326.49999999999994 272.50000000000006,326.50000000000006\" stroke=\"#42bc80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"272.50000000000006,326.50000000000006 272.49999999999994,272.50000000000006\" stroke=\"#44ba80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"272.49999999999994,272.50000000000006 328.49999999999994,272.49999999999994\" stroke=\"#47b780\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"328.49999999999994,272.49999999999994 328.50000000000006,330.49999999999994\" stroke=\"#49b580\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"328.50000000000006,330.49999999999994 268.50000000000006,330.50000000000006\" stroke=\"#4cb280\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"268.50000000000006,330.50000000000006 268.49999999999994,268.50000000000006\" stroke=\"#4faf80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"268.49999999999994,268.50000000000006 332.49999999999994,268.49999999999994\" stroke=\"#51ad80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"332.49999999999994,268.49999999999994 332.50000000000006,334.49999999999994\" stroke=\"#54aa80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"332.50000000000006,334.49999999999994 264.50000000000006,334.50000000000006\" stroke=\"#56a880\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"264.50000000000006,334.50000000000006 264.49999999999994,264.50000000000006\" stroke=\"#59a580\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"264.49999999999994,264.50000000000006 336.49999999999994,264.4999999999999\" stroke=\"#5ba380\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"336.49999999999994,264.4999999999999 336.5000000000001,338.4999999999999\" stroke=\"#5ea080\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"336.5000000000001,338.4999999999999 260.5000000000001,338.5000000000001\" stroke=\"#609e80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"260.5000000000001,338.5000000000001 260.4999999999999,260.5000000000001\" stroke=\"#639b80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"260.4999999999999,260.5000000000001 340.4999999999999,260.4999999999999\" stroke=\"#669980\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"340.4999999999999,260.4999999999999 340.5000000000001,342.4999999999999\" stroke=\"#689680\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"340.5000000000001,342.4999999999999 256.5000000000001,342.5000000000001\" stroke=\"#6b9380\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"256.5000000000001,342.5000000000001 256.4999999999999,256.5000000000001\" stroke=\"#6d9180\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"256.4999999999999,256.5000000000001 344.4999999999999,256.4999999999999\" stroke=\"#708e80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"344.4999999999999,256.4999999999999 344.5000000000001,346.4999999999999\" stroke=\"#728c80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"344.5000000000001,346.4999999999999 252.50000000000014,346.5000000000001\" stroke=\"#758980\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"252.50000000000014,346.5000000000001 252.4999999999999,252.5000000000001\" stroke=\"#778780\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"252.4999999999999,252.5000000000001 348.4999999999999,252.49999999999983\" stroke=\"#7a8480\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"348.4999999999999,252.49999999999983 348.50000000000017,350.49999999999983\" stroke=\"#7c8280\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"348.50000000000017,350.49999999999983 248.50000000000017,350.50000000000017\" stroke=\"#7f7f80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"248.50000000000017,350.50000000000017 248.49999999999983,248.50000000000014\" stroke=\"#827c80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"248.49999999999983,248.50000000000014 352.49999999999983,248.49999999999983\" stroke=\"#847a80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"352.49999999999983,248.49999999999983 352.50000000000017,354.49999999999983\" stroke=\"#877780\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"352.50000000000017,354.49999999999983 244.50000000000017,354.50000000000017\" stroke=\"#897580\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"244.50000000000017,354.50000000000017 244.49999999999983,244.50000000000017\" stroke=\"#8c7280\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"244.49999999999983,244.50000000000017 356.49999999999983,244.49999999999977\" stroke=\"#8e7080\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"356.49999999999983,244.49999999999977 356.5000000000002,358.4999999999998\" stroke=\"#916d80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"356.5000000000002,358.4999999999998 240.50000000000023,358.5000000000002\" stroke=\"#936b80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"240.50000000000023,358.5000000000002 240.49999999999977,240.5000000000002\" stroke=\"#966880\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"240.49999999999977,240.5000000000002 360.4999999999998,240.49999999999977\" stroke=\"#996680\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"360.4999999999998,240.49999999999977 360.5000000000002,362.4999999999998\" stroke=\"#9b6380\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"360.5000000000002,362.4999999999998 236.50000000000023,362.5000000000002\" stroke=\"#9e6080\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"236.50000000000023,362.5000000000002 236.49999999999977,236.50000000000023\" stroke=\"#a05e80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"236.49999999999977,236.50000000000023 364.4999999999998,236.49999999999972\" stroke=\"#a35b80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"364.4999999999998,236.49999999999972 364.5000000000003,366.4999999999997\" stroke=\"#a55980\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"364.5000000000003,366.4999999999997 232.50000000000028,366.5000000000003\" stroke=\"#a85680\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"232.50000000000028,366.5000000000003 232.49999999999972,232.50000000000028\" stroke=\"#aa5480\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"232.49999999999972,232.50000000000028 368.4999999999997,232.49999999999972\" stroke=\"#ad5180\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"368.4999999999997,232.49999999999972 368.5000000000003,370.4999999999997\" stroke=\"#af4f80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"368.5000000000003,370.4999999999997 228.50000000000028,370.5000000000003\" stroke=\"#b24c80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"228.50000000000028,370.5000000000003 228.4999999999997,228.50000000000028\" stroke=\"#b54980\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"228.4999999999997,228.50000000000028 372.49999999999966,228.49999999999966\" stroke=\"#b74780\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"372.49999999999966,228.49999999999966 372.50000000000034,374.49999999999966\" stroke=\"#ba4480\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"372.50000000000034,374.49999999999966 224.50000000000034,374.50000000000034\" stroke=\"#bc4280\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"224.50000000000034,374.50000000000034 224.49999999999966,224.50000000000034\" stroke=\"#bf3f80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"224.49999999999966,224.50000000000034 376.49999999999966,224.4999999999996\" stroke=\"#c13d80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"376.49999999999966,224.4999999999996 376.5000000000004,378.4999999999996\" stroke=\"#c43a80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"376.5000000000004,378.4999999999996 220.5000000000004,378.50000000000034\" stroke=\"#c63880\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"220.5000000000004,378.50000000000034 220.4999999999996,220.50000000000034\" stroke=\"#c93580\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"220.4999999999996,220.50000000000034 380.4999999999996,220.49999999999957\" stroke=\"#cc3380\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"380.4999999999996,220.49999999999957 380.50000000000045,382.49999999999955\" stroke=\"#ce3080\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"380.50000000000045,382.49999999999955 216.50000000000043,382.5000000000004\" stroke=\"#d12d80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"216.50000000000043,382.5000000000004 216.4999999999996,216.5000000000004\" stroke=\"#d32b80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"216.4999999999996,216.5000000000004 384.4999999999996,216.49999999999955\" stroke=\"#d62880\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"384.4999999999996,216.49999999999955 384.50000000000045,386.49999999999955\" stroke=\"#d82680\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"384.50000000000045,386.49999999999955 212.50000000000045,386.50000000000045\" stroke=\"#db2380\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"212.50000000000045,386.50000000000045 212.49999999999955,212.50000000000045\" stroke=\"#dd2180\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"212.49999999999955,212.50000000000045 388.49999999999955,212.4999999999995\" stroke=\"#e01e80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"388.49999999999955,212.4999999999995 388.5000000000005,390.4999999999995\" stroke=\"#e21c80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"388.5000000000005,390.4999999999995 208.5000000000005,390.50000000000045\" stroke=\"#e51980\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"208.5000000000005,390.50000000000045 208.4999999999995,208.50000000000048\" stroke=\"#e81680\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"208.4999999999995,208.50000000000048 392.4999999999995,208.49999999999943\" stroke=\"#ea1480\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"392.4999999999995,208.49999999999943 392.50000000000057,394.49999999999943\" stroke=\"#ed1180\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"392.50000000000057,394.49999999999943 204.50000000000057,394.5000000000005\" stroke=\"#ef0f80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"204.50000000000057,394.5000000000005 204.49999999999946,204.5000000000005\" stroke=\"#f20c80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"204.49999999999946,204.5000000000005 396.49999999999943,204.4999999999994\" stroke=\"#f40a80\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"396.49999999999943,204.4999999999994 396.5000000000006,398.49999999999943\" stroke=\"#f70780\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"396.5000000000006,398.49999999999943 200.50000000000063,398.50000000000057\" stroke=\"#f90580\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"200.50000000000063,398.50000000000057 200.49999999999943,200.50000000000057\" stroke=\"#fc0280\" stroke-linecap=\"round\" stroke-width=\"1\"/><polygon clip-path=\"url(#border_clip)\" fill=\"black\" fill-rule=\"evenodd\" points=\"200.49999999999943,200.50000000000057 191.49999999999937,195.50000000000063 193.49999999999943,200.50000000000063 191.49999999999943,205.50000000000063\" stroke=\"#fc0280\" stroke-width=\"1\"/></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "setup(600, 600)\n",
    "\n",
    "# Draw colorful spiral\n",
    "pensize(1)\n",
    "speed(0)\n",
    "\n",
    "for i in range(100):\n",
    "    # Color gradient\n",
    "    r = int(255 * (i / 100))\n",
    "    g = int(255 * ((100 - i) / 100))\n",
    "    b = 128\n",
    "    pencolor(f'#{r:02x}{g:02x}{b:02x}')\n",
    "    \n",
    "    forward(i * 2)\n",
    "    right(90)\n",
    "\n",
    "done()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7. Turtle State and Properties Demo\n",
    "\n",
    "Show how to get and set various turtle properties."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Initial position: (-100.00,0.00)\n",
      "Initial heading: 0.0°\n",
      "Position after move: (-50.00,0.00)\n",
      "Current heading: 0.0°\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" baseProfile=\"full\" height=\"400px\" version=\"1.1\" width=\"400px\"><defs/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"100.5,200.5 150.5,200.5\" stroke=\"black\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"150.5,200.5 180.5,200.5 150.5,200.5\" stroke=\"#ff0000\" stroke-linecap=\"round\" stroke-width=\"3\"/><polygon clip-path=\"url(#border_clip)\" fill=\"black\" fill-rule=\"evenodd\" points=\"150.5,200.5 132.5,190.5 136.5,200.5 132.5,210.5\" stroke=\"#ff0000\" stroke-width=\"2\"/></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "setup(400, 400)\n",
    "\n",
    "# Set initial position and direction\n",
    "penup()\n",
    "goto(-100, 0)\n",
    "pendown()\n",
    "setheading(0)\n",
    "\n",
    "print(f\"Initial position: {position()}\")\n",
    "print(f\"Initial heading: {heading()}°\")\n",
    "\n",
    "# Move and check state\n",
    "forward(50)\n",
    "print(f\"Position after move: {position()}\")\n",
    "print(f\"Current heading: {heading()}°\")\n",
    "\n",
    "# Draw an arrow to show current direction\n",
    "pensize(3)\n",
    "pencolor('red')\n",
    "forward(30)\n",
    "backward(30)\n",
    "\n",
    "# Show turtle\n",
    "showturtle()\n",
    "stamp_size(2, 2, 2)  # Set stamp size\n",
    "\n",
    "done()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 8. Error Handling and Edge Cases\n",
    "\n",
    "Demonstrate some edge cases and error handling."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" baseProfile=\"full\" height=\"300px\" version=\"1.1\" width=\"300px\"><defs/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"350.5,-49.5 400.5,-49.5\" stroke=\"#0000ff\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"-49.5,350.5 0.5,350.5\" stroke=\"#ff0000\" stroke-linecap=\"round\" stroke-width=\"1\"/><polyline clip-path=\"url(#border_clip)\" fill=\"none\" points=\"150.5,150.5 150.5,150.5\" stroke=\"#008000\" stroke-linecap=\"round\" stroke-width=\"1\"/><polygon clip-path=\"url(#border_clip)\" fill=\"black\" fill-rule=\"evenodd\" points=\"150.5,150.5 132.5,140.5 136.5,150.5 132.5,160.5\" stroke=\"#008000\" stroke-width=\"2\"/></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Test edge cases\n",
    "setup(300, 300)\n",
    "\n",
    "# Test movement beyond boundaries\n",
    "penup()\n",
    "goto(200, 200)  # Beyond canvas boundaries\n",
    "pendown()\n",
    "pencolor('blue')\n",
    "forward(50)\n",
    "\n",
    "# Test negative values\n",
    "penup()\n",
    "goto(-200, -200)\n",
    "pendown()\n",
    "pencolor('red')\n",
    "forward(50)\n",
    "\n",
    "# Test zero values\n",
    "penup()\n",
    "goto(0, 0)\n",
    "pendown()\n",
    "pencolor('green')\n",
    "forward(0)\n",
    "right(0)\n",
    "\n",
    "done()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Summary\n",
    "\n",
    "The `svg_turtle_classic` module provides three flexible usage modes:\n",
    "\n",
    "1. **Procedural style**: Suitable for simple drawing tasks\n",
    "2. **Module style**: Suitable for scenarios requiring clear namespaces\n",
    "3. **Object-oriented style**: Suitable for complex multi-turtle drawings\n",
    "\n",
    "Main features:\n",
    "- SVG output support, suitable for display in Jupyter environments\n",
    "- Compatible with classic turtle module API\n",
    "- Support for various drawing modes (lines, fills, text, etc.)\n",
    "- Support for color and style settings\n",
    "- Support for turtle state management\n",
    "\n",
    "This module is an excellent tool for learning programming and visualization!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
